package com.hns.phone.pushMsg.service;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.frame.service.CommonService;
import com.hns.phone.entity.BiDayReportRoleInfoEntity;
import com.hns.phone.entity.SysAppCanPhoneRelEntity;
import com.hns.phone.pushMsg.vo.PushMsgDataVo;
import com.hns.tool.pub.PubUtil;

/**
 * 推送报警数据service
 * @author:zhangy
 * @email:zhangyu2222z@sina.cn
 * @version Revision 2.0.0
 */
@Service
public class PushAlarmService extends CommonService {

	/**
	 * 查询推送报警数据
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings("unchecked")
	public List<PushMsgDataVo> getAlarmData(){
		List<PushMsgDataVo> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("pushMsg.getAlarmData"), PushMsgDataVo.class);
		return list;
	}

	/**
	 * 更新今日报告
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings("unchecked")
	@Transactional
	public void updateDayReport() {
		//清空1小时之前的今日报告
		this.sqlMapDao.delete("pushMsg.deleteDayReport");
		List<BiDayReportRoleInfoEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("pushMsg.searchDayReport"), BiDayReportRoleInfoEntity.class);
//		String corpId = this.getAppCurrentUser().getUser().getCorpId();
//		int count = 0;
		for(int i=0;i<list.size();i++){
//			count++;
			BiDayReportRoleInfoEntity entity = list.get(i);
//			entity.setCorpId(corpId);
			entity.setCrtTime(new Date());
			this.sqlMapDao.insert("pushMsg.addDayReportData", entity);
			
		}
	}

	
	/**
	 * 获取角色对应用户token
	 * @param roleId
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings("unchecked")
	public List<SysAppCanPhoneRelEntity> getUserTokens(PushMsgDataVo params) {
		List<SysAppCanPhoneRelEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("pushMsg.getUserTokens", params), SysAppCanPhoneRelEntity.class);
		return list;
		
	}
	
}
